home *** CD-ROM | disk | FTP | other *** search
- Generalized BinarySearch function for anything ( bsearch.m )
-
- © Richard Perrott 6th April 1995 FreeWare
- email: hcm94rp2@dmu.ac.uk
-
- This module implements the binary sort algorithm in the most flexible way.
-
- PROC bsearch(base,first,last,find,comp) /* : LONG */
-
- base:
- the start address of an ARRAY OF ? e.g. CHAR, INT, LONG, OBJECT ?.
-
- first:
- the lowest position you want to search from
-
- last:
- the highest position you want to search to
-
- find:
- the item to find: value/pointer to value/etc
-
- comp:
- a pointer to a PROC to compare the value at position
- with the value for find.
-
- e.g.
-
- PROC comp(base:PTR TO LONG, position, find:LONG)
- DEF item
-
- item := base[position]
- IF item1 < find THEN RETURN -1
- IF item1 > find THEN RETURN 1
- ENDPROC 0
-
-
- If search failsThe result is -1 ($FFFFFFFF) if search fails.
-
- Note:
- Any registers it uses are saved, but if your comp routine
- uses registers other than D0/D1/D2/A0 and the caller of bsearch
- needs them, then you will need to save them. bsearch doesn't
- care which registers you use.
-
- The module contains 96 bytes of assembler / E code.
-
- The routine will only stay in a 68020+ code cache if the
- PROC comp it calls is small and very close to it.
-
- The routine has been heavily tested, though there are no promises
- and I won't be held responsible if you find bugs or you misuse the
- routine.
-
- If you do find any bugs then please email me.
-
- References:
- Programming and Problem Solving in Modula-2, Sanford Leestma
- & Larry Nyhoff, © Macmillan 1992, USA, page 380-381
-